import 'package:flutter/material.dart';

import 'FoodBean.dart';

class GridDemo extends StatelessWidget {
  const GridDemo({super.key});

  @override
  Widget build(BuildContext context) {
    final List<FoodBean> functions = [
      const FoodBean('assets/images/grid/sandwich.png', '三明治'),
      const FoodBean('assets/images/grid/lollipop.png', '棒棒糖'),
      const FoodBean('assets/images/grid/steamed_stuffed_bun.png', '包子'),
      const FoodBean('assets/images/grid/popcorn.png', '爆米花'),
      const FoodBean('assets/images/grid/ice_cream.png', '冰淇淋'),
      const FoodBean('assets/images/grid/cookie.png', '饼干'),
      const FoodBean('assets/images/grid/pudding.png', '布丁'),
      const FoodBean('assets/images/grid/cake.png', '蛋糕'),
      const FoodBean('assets/images/grid/egg_tart.png', '蛋挞'),
      const FoodBean('assets/images/grid/bream_cake.png', '稠鱼烧'),
    ];
    
    return Scaffold(
      appBar: AppBar(title: const Text('GRID')),
      // 创建换行布局
      body: GridView(
        padding: const EdgeInsets.symmetric(vertical: 0),
        gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 3,//子控件的最大宽度
          childAspectRatio: 0.5,//设置每个元素大小（宽高比）
          crossAxisSpacing: 20,//设置子控件左右距离
          mainAxisSpacing: 30,//设置子控件上下距离
        ),

        children: List.generate(
          functions.length,
            (index) => Column(
              children: [
                SizedBox(
                  width: 100,
                  height: 150,
                  child: FittedBox(
                    fit: BoxFit.scaleDown,
                    child: Image.asset(
                      functions[index].picPath,
                      width: 50,
                      height: 50,
                    ),
                  ),
                ),
                Text(
                  functions[index].text,
                ),
              ],
            ),
        ),
      ),
    );
  }
}